<script setup lang="ts">
import FinanciaTableYOY from '@/components/Echart/Table/FinanciaTableYOY.vue'
import FinanciaDialog from '@/components/Echart/Table/FinanciaDialog.vue'
import AnimationDialog from '@/components/Dialog/AnimationDialog.vue'
import { reactive, watch, ref, nextTick } from 'vue'
import { storeToRefs } from 'pinia'
import { useFinanceStore } from '@/stores/module/finance'
const FinanceStore = useFinanceStore() // 创建store实例
const { getProfitMom } = storeToRefs(FinanceStore)

const lineValuesCnRegion = getProfitMom.value?.info[0]?.line?.value[0]
const lineValuesEuAsiaRegion = getProfitMom.value?.info[0]?.line?.value[1]
const lineValuesAsiaPacificRegion = getProfitMom.value?.info[0]?.line?.value[2]
const lineValuesAmericaRegion = getProfitMom.value?.info[0]?.line?.value[3]
const lineValuesAfricaRegion = getProfitMom.value?.info[0]?.line?.value[4]
const mothHeadData = getProfitMom.value?.info[0].tableHeadData

const tableHeadData = reactive([
  getProfitMom.value.titleMonth, // 先把 titleMonth 放进去
  ...getProfitMom.value?.sub_titles,
])

const tableBodyData = reactive(
  mothHeadData?.map((title, index) => ({
    id: index.toString(),
    name: title,
    cnRegion: lineValuesCnRegion[index],
    euAsiaRegion: lineValuesEuAsiaRegion[index],
    asiaPacificRegion: lineValuesAsiaPacificRegion[index],
    americaRegion: lineValuesAmericaRegion[index],
    africaRegion: lineValuesAfricaRegion[index],
  }))
)

const title = ref(getProfitMom.value.titleRate)

const dialogInfo = {
  title: title.value, // 标题
  style: 'lb', // 弹窗位置，例如右中
  width: '50%', // 宽度
}
const dialog = ref(null)
const btn = async () => {
  await nextTick()
  dialog.value.changeDialogVisible(true)
}
</script>
<template>
  <card-box>
    <template v-slot:title>
      <h1>{{ getProfitMom.titleRate }}</h1>
    </template>
    <button
      @click="btn"
      class="see-more-btn"
      size="small"
      v-if="tableBodyData.length > 3"
    >
      {{ $t('bi_front_distributorseemore') }}
    </button>
    <FinanciaTableYOY
      :table-head-data="tableHeadData"
      :table-body-data="tableBodyData"
      v-if="tableBodyData.length && tableHeadData.length"
    />
    <div v-else class="default-img">
      <p>{{ $t('bi_common_nodata') }}</p>
    </div>
  </card-box>

  <AnimationDialog
    ref="dialog"
    :dialogInfo="dialogInfo"
    class="transactionData"
    style="background-color: rgba(11, 31, 86, 0.5)"
  >
    <FinanciaDialog
      :table-head-data="tableHeadData"
      :table-body-data="tableBodyData"
      :title="title"
    /> </AnimationDialog
  >
</template>
<style lang="scss" scoped>
.default-img {
  width: 100%;
  text-align: center;
  padding: 120px 0;
  background-image: url('@/assets/images/canvsimage/default.png');
  background-repeat: no-repeat;
  background-position: center;
  font-size: 16px;
  color: #00f6ff;
}

.see-more-btn {
  position: relative;
  z-index: 100;
  width: 100px;
  height: 25px;
  text-align: center;
  float: right;
  margin-top: -30px;
  font-size: 10px;
  background-color: rgba(0, 53, 171, 0.8);
  border: 1px solid #0b45ca;
  color: #00f6ff;
  cursor: pointer;
}
.dialog-fade-enter-active .el-dialog.transactionData {
  animation: tilt-in-left 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes tilt-in-left {
  0% {
    -webkit-transform: rotateX(-30deg) translateX(-300px) skewX(-30deg);
    transform: rotateX(-30deg) translateX(-300px) skewX(-30deg);
    opacity: 0;
  }
  100% {
    -webkit-transform: rotateX(0deg) translateX(0) skewX(0deg);
    transform: rotateX(0deg) translateX(0) skewX(0deg);
    opacity: 1;
  }
}
</style>
